#pragma once

#include <functional>

#include "../utility/Noncopyable.h"
#include "../net/Socket.h"
#include "./Channel.h"

class InetAddress;
class EventLoop;

class Acceptor : Noncopyable
{
public:
    using NewConnCallback = std::function<void(int sockFd, const InetAddress &)>;

    Acceptor(EventLoop *loop, const InetAddress &listenAddr, bool reusePort);
    ~Acceptor();

    void setNewConnCallback(const NewConnCallback &cb);
    bool getIsListen() const;

    void listen();

private:
    void handleRead(); // 新连接回调1

    EventLoop *loop_;       // 所属loop，就是用户定义的mainLoop
    Socket acceptSocket_;   // listen fd
    Channel acceptChannel_; // listen channel
    // 新连接回调2TcpServer::newConnection()
    // connfd => 打包成Channel => 唤醒subloop
    NewConnCallback newConnCallback_;
    bool isListen_; // 是否在监听
};